//
//  BaseModel.m
//  项目一
//
//  Created by 王鑫 on 15/11/17.
//  Copyright (c) 2015年 王鑫. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel
#pragma mark - Method baseModelByArr
+ (NSMutableArray *)baseModelByArr:(NSArray *)arr {
    // 初始化容器modelArr
    NSMutableArray *modelArr = [NSMutableArray array];
    // 对数组进行遍历
    for (NSDictionary *dic in arr) {
        // 添加一个自动释放池 /越出范围则被自动释放
        @autoreleasepool {
            // 通过遍历构造器来创建对象
            id model = [[self class] baseModelWithDic:dic];
            [modelArr addObject:model];
        }
    }
    return modelArr;
}
#pragma mark - Method baseModelWithDic
+ (instancetype)baseModelWithDic:(NSDictionary *)dic {
    // 通过多态创建对象 / 进行自动释放
    id model = [[[[self class] alloc] initWithDic:dic] autorelease];
    return model;
}
#pragma mark - Method initWithDic
- (instancetype)initWithDic:(NSDictionary *)dic {
    self = [super init];
    if (self) {
        // 进行KVC赋值
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
#pragma mark - Method forUndefinedKey
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}
@end
